package com.tanhua.server.controller;

import com.tanhua.domain.db.UserInfo;
import com.tanhua.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/users")
public class UserInfoController {
    @Autowired
    private UserService userService;

    /**
     * 查询当前用户的信息
     * 请求链接:GET:/users
     * 请求参数:
     *          Headers:Authorization
     * 返回值:
     *          userinfo
     */
    @GetMapping
    public ResponseEntity userInfo(){
        return userService.findUserInfo();
    }

    /**
     * 更新用户信息
     * 请求链接:PUT/users
     * 请求参数:
     *          Headers：Authorization
     *          Body:userinfo
     *返回值:
     *      null
     */
    @PutMapping
    public ResponseEntity updateUserInfo(@RequestBody UserInfo userInfo){
        return userService.updateUserInfo(userInfo);
    }

    /**
     * 保存头像
     * 请求链接:POST/users/header
     * 请求参数:
     *          Headers：Authorization
     *          Body:headPhoto头像图片 (Spring MVC中 )
     * 返回值:
     *          null
     */
    @PostMapping("/header")
    public ResponseEntity header(
                                 MultipartFile headPhoto) throws IOException {
        return userService.updateheader(headPhoto);
    }
}
